#include "mycoin.h"
#include "qdebug.h"
//MyCoin::MyCoin(QWidget *parent) : QPushButton(parent)
//{

//}
MyCoin::MyCoin(QString btimg){

    QPixmap pix;
    bool rt=pix.load(btimg);
    if(!rt)
    {
        qDebug()<<"error";
    }
    this->setFixedSize(pix.width(),pix.height());
    this->setStyleSheet("QPushButton{border:0px}");
    this->setIcon(pix);
    this->setIconSize(pix.size());
    timer1=new QTimer(this);
    timer2=new QTimer(this);
    connect(timer1,&QTimer::timeout,[=](){
        QString str = QString(":/res/Coin000%1.png").arg(this->min++);

               QPixmap pix;
               pix.load(str);

               this->setFixedSize(pix.width()*1, pix.height()*1);

               this->setStyleSheet("QPushButton{border:0px;}");
               this->setIcon(pix);
               this->setIconSize(QSize(pix.width(), pix.height()));

               if(this->min > this->max){
                   this->min = 1;
                   timer1->stop();
                   this->animation=false;
               }
    });
    connect(timer2,&QTimer::timeout,[=](){
        QString str = QString(":/res/Coin000%1.png").arg(this->max--);

               QPixmap pix;
               pix.load(str);

               this->setFixedSize(pix.width()*1, pix.height()*1);

               this->setStyleSheet("QPushButton{border:0px;}");
               this->setIcon(pix);
               this->setIconSize(QSize(pix.width(), pix.height()));

               if(this->min > this->max){
                   this->max = 8;

                   timer2->stop();
                   this->animation=false;
               }
    });
}
void MyCoin::mousePressEvent(QMouseEvent *e){
    if(this->animation ){
        return;
    }
    QPushButton::mousePressEvent(e);
}
void MyCoin::changFlg(){
    if(this->flag)
    {
        timer1->start(30);
        this->flag=false;
    }
    else
    {
        timer2->start(30);
        this->flag=true;
    }
    this->animation=true;
}
